package Day1;

import java.util.Scanner;

public class Paixu_2 {
    public static void main(String[] args) {
        int []arr=new int[10];
        int len=4;
        Paixu_2.input(arr,len);
        System.out.println("请输入你的查找数据");
        Scanner scanner = new Scanner(System.in);
        int data=scanner.nextInt();
        if (Paixu_2.findData(arr,len,data)){
           System.out.println("查找成功");
        }else{
          System.out.println("查找失败");
       }
       if (Paixu_2.delData(arr,len,data)) {
           System.out.println("删除成功");
         Paixu_2.output(arr,len-1);
        }else{
           System.out.println("删除失败");
          Paixu_2.output(arr,len);
        }


    }

    public static void input(int []arr,int len) {
        System.out.println("请给数组输入连续的"+len+"数据");
        Scanner scanner = new Scanner(System.in);
        for (int i = 0; i < len; i++) {
            arr[i]= scanner.nextInt();
        }
    }
    public static void output(int[]arr,int len) {
        for (int i = 0; i < len; i++) {
            System.out.print(" " + arr[i]);
        }
        System.out.println();
    }

    public static boolean findData(int[]arr,int len,int data){
        for (int i = 0; i < len; i++) {
            if (arr[i]==data){
                return true;
            }
        }
        return  false;
    }
    public static boolean delData(int[]arr,int len,int data){
        int x=0,i;
        for (i = 0; i < len; i++) {
            if (arr[i]==data){
                x=i;
                break;
            }
        }
        if (i==len){
            return false;
        }else{
            for (int j = x; j < len-1; j++) {
                arr[j]=arr[j+1];
            }
            return true;
        }
    }
}
